Skip to content

fix(studio): a sealed undo or redo of a keyframe edit re-runs in place instead of reloading - #8272

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/sealed-undo-script-in-place
Nov 20, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/sealed-undo-script-in-place

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

In a sealed preview (Studio cannot script the frame), an undo or redo of an edit saved into the GSAP script now re-runs the restored script in place. Before, it reloaded the whole preview. That covers every move, resize or rotate of an animated layer saved as a keyframe. The preview no longer blanks and rebuilds on each such undo or redo, and it shows the restored state as soon as the frame answers.

Why

gsapUndoRestore.ts turned any undo whose script text changed into a full reload. Its comment said a sealed preview could not yet be asked to re-run a script. Since #8158 it can: an edit already re-runs its script in a sealed frame through the soft-reload request. Undo and redo were never routed to it. A same-origin preview already re-runs the restored script in place for the same undo.

How

Core:

  • softReload.ts: a soft-reload request also carries restore, the restored attributes of the elements the undo changed, in the same shape restore-attributes takes (empty for an edit).
    • The frame plans them with restore-attributes' own planner before touching anything. That keeps one set of rules for which attributes may be set or dropped, all or nothing.
    • Inside the re-run, the frame sets them first, before the timing and the script, as the timing of a timing edit already is.
    • If the plan refuses any attribute, the whole request answers cannot-soft-reload and nothing changes.
  • restoreAttributes.ts: the scope parser, the planner and the apply step are exported for that. restore-attributes itself behaves as before.

Studio:

  • gsapUndoRestore.ts: when the active file's script changed, a sealed undo or redo sends one soft-reload with the restored script, the restored file's authored styles, what the outgoing script set, and the restored attributes. Any refusal reloads the preview as before. It still reloads when a file other than the active one changed its script, when several scripts changed, or when restoring the attributes is refused. The stale comment is gone.
  • gsapSoftReload.ts: the sealed re-run passes restore through (empty for an edit).

Related work

Builds on #8158. #8264 (open) adds a rule to restore-attributes for marks the page's reapply script keeps; whichever lands second moves that rule into the shared planner, so this request follows it too.

Test plan

  • softReload.test.ts:
    • an undo's restored attributes are set before the re-run (the rebind sees them), and a dropped Studio mark is gone;
    • a restore carrying an attribute the planner refuses (onclick) refuses the whole request: the style, the script and the timelines stay as they were;
    • the parser refuses a request with no restore field or a restore element keyed by neither id.
  • gsapUndoRestore.sealed.test.ts: a sealed undo whose script changed sends one soft-reload with the restored script and the changed attributes (or none when only the script changed), and does not reload; a cannot-soft-reload answer reloads.
  • gsapSoftReload.sealed.test.ts: an edit's request carries an empty restore.

fails without the fix: with the frame never setting the restored attributes, the first softReload test fails; with an unsafe restore not refusing the request, the second fails; with the old script-changed reload in sealedFile, both re-run cases of the sealed undo test fail.

Run on Linux at this head: core softReload, restoreAttributes, editingAgent, editingPort and Studio's five touched test files pass three runs in a row; core and Studio tsc no errors; format clean; the code audit passes.

Bench

Edit-accuracy bench, sealed preview on (the sealed-by-default change, #8263 and #8271 merged with this branch), the redo cases the reload made miss, run one at a time with a trace, twice before and twice after:

cases redo path before redo off before redo path after redo off after
move of a tweened layer, root, 50% zoom (px and %) full reload 0, 108; 108, 108 in place 0, 0; 0, 0
rotate of a held or tweened layer, root, 50% zoom full reload 62, 0; 0, 62 in place 0, 0; 0, 0
resize of a tweened layer (%), root, 50% zoom full reload 120, 0 full reload 120, 0
five cases in a nested composition reload same before and after reload same before and after

The resize goes in place only with #8264. On main it still reloads, because its restore sets Studio's own data-hf-studio-* marks, which restore-attributes does not set until #8264. With #8264 merged in (traced), it restores in place and its redo is 0 px off.

The nested cases still reload, because their script lives in a sub-composition file. Their drop is also off, before and after; that is a known separate miss.

Before

Sealed preview, a layer its tween moves, moved and undone, then redone. Counted from the redo key: the preview loads two new documents (the full reload), and the box reaches the saved place after 385 ms.

before: a redo reloads the preview

After

The same redo: no new preview document, and the box is at the saved place after 56 ms.

after: a redo re-runs the script in place

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 50 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@eddy-heygen eddy-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Eddy's agent) Reviewed by Eddy's Claude agent at commit 8b5096c (non-test diff read by me).

Verdict: approve.

Summary
In a sealed preview, undoing or redoing an edit that also changed the animation script reloaded the whole preview. The soft-reload request now carries the restored attributes, and the frame applies them and re-runs its script in place.

What I checked

  • The new restore field is parsed by the same scope parser the existing restore request uses, with the same limits on the number of scopes and elements; a request without the exact field set is refused.
  • The frame plans the restore first and answers "cannot soft reload" if any element is missing, not the file's own, or unsafe to change, before anything is modified; the caller then falls back to a full reload.
  • The attribute writes go through one shared function used by both paths, so the restore applies the same drop-and-set rules as before.
  • On the Studio side a failed or refused soft reload still ends in a full reload.

CI: 88 pass, 11 skipped, none failing or pending.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 4fd96e3 Nov 20, 2026
99 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-undo-script-in-place branch November 20, 2026 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants